package com.wilmer.classTests.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.classTests.domain.YwClassTests;
import com.wilmer.classTests.service.IYwClassTestsService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 随堂测试管理Controller
 *
 * @author zl
 * @date 2024-04-10
 */
@RestController
@RequestMapping("/classTests/classTests")
public class YwClassTestsController extends BaseController {
    @Autowired
    private IYwClassTestsService ywClassTestsService;

    /**
     * 查询随堂测试管理列表
     */
    @PreAuthorize("@ss.hasPermi('classTests:classTests:list')")
    @GetMapping("/list")
    public TableDataInfo list(YwClassTests ywClassTests) {
        startPage();
        List<YwClassTests> list = ywClassTestsService.selectYwClassTestsList(ywClassTests);
        return getDataTable(list);
    }

    /**
     * 发起测试
     */
    @GetMapping("/startTest")
    public AjaxResult startTest(@Param("testId") Long testId, @Param("courseId") Long courseId) {
        return success(ywClassTestsService.startTest(testId, courseId));
    }

    /**
     * 导出随堂测试管理列表
     */
    @PreAuthorize("@ss.hasPermi('classTests:classTests:export')")
    @Log(title = "随堂测试管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwClassTests ywClassTests) {
        List<YwClassTests> list = ywClassTestsService.selectYwClassTestsList(ywClassTests);
        ExcelUtil<YwClassTests> util = new ExcelUtil<YwClassTests>(YwClassTests.class);
        util.exportExcel(response, list, "随堂测试管理数据");
    }

    /**
     * 获取随堂测试管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('classTests:classTests:query')")
    @GetMapping(value = "/{testId}")
    public AjaxResult getInfo(@PathVariable("testId") Long testId) {
        return success(ywClassTestsService.selectYwClassTestsByTestId(testId));
    }

    /**
     * 新增随堂测试管理
     */
    @PreAuthorize("@ss.hasPermi('classTests:classTests:add')")
    @Log(title = "随堂测试管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwClassTests ywClassTests) {
        return toAjax(ywClassTestsService.insertYwClassTests(ywClassTests));
    }

    /**
     * 修改随堂测试管理
     */
    @PreAuthorize("@ss.hasPermi('classTests:classTests:edit')")
    @Log(title = "随堂测试管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwClassTests ywClassTests) {
        return toAjax(ywClassTestsService.updateYwClassTests(ywClassTests));
    }

    /**
     * 删除随堂测试管理
     */
    @PreAuthorize("@ss.hasPermi('classTests:classTests:remove')")
    @Log(title = "随堂测试管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{testIds}")
    public AjaxResult remove(@PathVariable Long[] testIds) {
        return toAjax(ywClassTestsService.deleteYwClassTestsByTestIds(testIds));
    }
}
